﻿using System;
using System.Collections.Generic;
using System.Text;
using SharpSqlAnalyzer.pp.mediator;
using SharpSqlAnalyzer.pp.mediator.type;
using SharpSqlAnalyzer.pp.para;
using SharpSqlAnalyzer.pp.para.styleenums;
using SharpSqlAnalyzer.pp.utils;
using SharpSqlAnalyzer.stmt.db2;
using SharpSqlAnalyzer.stmt.mssql;
using SharpSqlAnalyzer.stmt.mysql;

namespace SharpSqlAnalyzer.pp.stmtformatter.type.comm
{
	// Token: 0x020001FD RID: 509
	public class AllStmtsFormatter : AbstractAllStmtsFormatter
	{
		// Token: 0x060011E1 RID: 4577 RVA: 0x003166D1 File Offset: 0x003148D1
		public override void doFormat(TStatementList stmts)
		{
			if (stmts == null || stmts.size() == 0)
			{
				return;
			}
			AllStmtsFormatter.processEmptyLine(stmts, this.Option, false);
			this.processComment(stmts);
			this.processTab(stmts);
			this.processLineNumber(stmts);
		}

		// Token: 0x060011E2 RID: 4578 RVA: 0x00316701 File Offset: 0x00314901
		public override void beforeFormat(TStatementList stmt)
		{
			if (stmt == null || stmt.size() == 0)
			{
				return;
			}
			this.processFormatFlag(stmt);
			this.alignLine(stmt);
		}

		// Token: 0x060011E3 RID: 4579 RVA: 0x0031671D File Offset: 0x0031491D
		public override void afterFormat(TStatementList stmt)
		{
			if (stmt != null)
			{
				stmt.size();
			}
		}

		// Token: 0x060011E4 RID: 4580 RVA: 0x0031672C File Offset: 0x0031492C
		private void processComment(TStatementList stmts)
		{
			bool removeComment = this.Option.removeComment;
			TSourceToken startToken = stmts.get(0).startToken;
			if (startToken == null)
			{
				return;
			}
			TSourceTokenList container = startToken.container;
			SourceTokenTextTempMediator mediator = MediatorFactory.getMediator<SourceTokenTextTempMediator>(typeof(SourceTokenTextTempMediator), this.Option.sessionId);
			for (int i = 0; i < container.size(); i++)
			{
				TSourceToken tsourceToken = container.get(i);
				if (tsourceToken.tokentype == ETokenType.ttsimplecomment || tsourceToken.tokentype == ETokenType.ttbracketedcomment)
				{
					if (tsourceToken.astext != null && (tsourceToken.astext.Contains("--begin_no_format") || tsourceToken.astext.Contains("--end_no_format")))
					{
						if (tsourceToken.astext.Contains("--begin_no_format"))
						{
							SourceTokenOperator.addBefore(this.Option, tsourceToken, SourceTokenOperator.createReturnSourceToken());
						}
					}
					else
					{
						bool flag = this.dealReturnComment(container, mediator, i, tsourceToken);
						if (tsourceToken.tokentype == ETokenType.ttsimplecomment && this.Option.compactMode != TCompactMode.Cpmugly)
						{
							bool flag2 = false;
							int j = tsourceToken.posinlist - 1;
							while (j >= 0)
							{
								TSourceToken tsourceToken2 = container.get(j);
								if (tsourceToken2.tokentype == ETokenType.ttwhitespace)
								{
									j--;
								}
								else
								{
									if (tsourceToken2.astext.StartsWith("/*+"))
									{
										flag2 = true;
										break;
									}
									break;
								}
							}
							if (!flag2)
							{
								List<TSourceToken> list = new List<TSourceToken>();
								int k = tsourceToken.posinlist + 1;
								bool flag3 = false;
								while (k < container.size())
								{
									TSourceToken tsourceToken3 = container.get(k);
									if (tsourceToken3.tokentype == ETokenType.ttreturn)
									{
										tsourceToken3.astext = "\n";
										break;
									}
									bool flag4 = false;
									TSourceTokenList tokensBefore = tsourceToken3.TokensBefore;
									if (tokensBefore != null)
									{
										for (int l = 0; l < tokensBefore.size(); l++)
										{
											if (tokensBefore.get(l).tokentype == ETokenType.ttreturn)
											{
												flag4 = true;
												break;
											}
										}
									}
									if (flag4)
									{
										break;
									}
									if (!flag3 && tsourceToken3.tokentype != ETokenType.ttwhitespace)
									{
										flag3 = true;
									}
									if (tsourceToken3.ReplaceToken != SourceTokenConstant.EMPTY)
									{
										list.Add(tsourceToken3);
									}
									k++;
								}
								if (list.Count > 0)
								{
									if (flag)
									{
										for (k = tsourceToken.posinlist; k >= 0; k--)
										{
											TSourceToken tsourceToken4 = container.get(k);
											if (tsourceToken4.tokentype == ETokenType.ttreturn)
											{
												break;
											}
											bool flag5 = false;
											TSourceTokenList tokensBefore2 = tsourceToken4.TokensBefore;
											if (tokensBefore2 != null)
											{
												for (int m = 0; m < tokensBefore2.size(); m++)
												{
													if (tokensBefore2.get(m).tokentype == ETokenType.ttreturn)
													{
														flag5 = true;
														break;
													}
												}
											}
											if (flag5)
											{
												break;
											}
										}
									}
									else
									{
										k = tsourceToken.posinlist - 1;
									}
									if (k > 0)
									{
										k = SourceTokenSearcher.lastNotWhitespaceAndReturnToken(container, 0, k).posinlist;
									}
									int num = 0;
									if (num < list.Count)
									{
										TSourceToken tsourceToken5 = list[num];
										if (tsourceToken5.tokentype == ETokenType.ttsimplecomment || tsourceToken5.tokentype == ETokenType.ttbracketedcomment)
										{
											this.dealReturnComment(container, mediator, tsourceToken5.posinlist, tsourceToken5);
											this.removeComment(container, this.Option, new bool?(removeComment), tsourceToken5, k + num + 1);
										}
										container.remove(tsourceToken5.posinlist);
										for (int n = k + num + 1; n < tsourceToken5.posinlist; n++)
										{
											container.get(n).posinlist++;
										}
										container.add(k + num + 1, tsourceToken5);
										tsourceToken5.posinlist = k + num + 1;
										i++;
									}
								}
							}
							this.removeComment(container, this.Option, new bool?(removeComment), tsourceToken, i);
						}
					}
				}
			}
			for (int num2 = 0; num2 < container.size(); num2++)
			{
				TSourceToken tsourceToken6 = container.get(num2);
				if (tsourceToken6.tokentype == ETokenType.ttsimplecomment && this.Option.compactMode != TCompactMode.Cpmugly)
				{
					int num3 = tsourceToken6.posinlist + 1;
					if (num3 < container.size())
					{
						TSourceToken tsourceToken7 = container.get(num3);
						bool flag6 = false;
						while ((tsourceToken7.ReplaceToken == SourceTokenConstant.EMPTY || (tsourceToken7.ReplaceToken == null && tsourceToken7.tokentype == ETokenType.ttwhitespace)) && tsourceToken7.posinlist < container.size() - 1)
						{
							tsourceToken7 = container.get(tsourceToken7.posinlist + 1);
							if (tsourceToken7.TokensBefore != null)
							{
								for (int num4 = 0; num4 < tsourceToken7.TokensBefore.size(); num4++)
								{
									if (tsourceToken7.TokensBefore.get(num4).tokentype == ETokenType.ttreturn)
									{
										flag6 = true;
										break;
									}
								}
							}
						}
						if (!flag6 && tsourceToken7.TokensBefore != null)
						{
							for (int num5 = 0; num5 < tsourceToken7.TokensBefore.size(); num5++)
							{
								if (tsourceToken7.TokensBefore.get(num5).tokentype == ETokenType.ttreturn)
								{
									flag6 = true;
									break;
								}
							}
						}
						if (!flag6 && tsourceToken7.ReplaceToken != SourceTokenConstant.EMPTY && !flag6)
						{
							if (tsourceToken7.ReplaceToken != null)
							{
								if (tsourceToken7.ReplaceToken.astext.IndexOf("\n") == -1)
								{
									SourceTokenOperator.addBefore(this.Option, tsourceToken7, SourceTokenOperator.createReturnSourceToken());
								}
							}
							else if (tsourceToken7.astext.IndexOf("\n") == -1)
							{
								int length = SourceTokenOperator.curColumnNumberVT(tsourceToken7);
								SourceTokenOperator.addBefore(this.Option, tsourceToken7, SourceTokenOperator.createReturnSourceToken());
								SourceTokenOperator.addBefore(this.Option, tsourceToken7, SourceTokenOperator.createWhitespaceSourceToken(length));
							}
						}
					}
				}
			}
		}

		// Token: 0x060011E5 RID: 4581 RVA: 0x00316C84 File Offset: 0x00314E84
		private bool dealReturnComment(TSourceTokenList list, SourceTokenTextTempMediator mediator, int i, TSourceToken t)
		{
			bool flag = false;
			if (i > 1)
			{
				TSourceToken tsourceToken = list.get(i - 1);
				if (AllStmtsFormatter.countLine(mediator.get(new int?(tsourceToken.posinlist))) > 0)
				{
					TSourceTokenList tokensBefore = t.TokensBefore;
					if (tokensBefore != null && tokensBefore.size() > 0)
					{
						for (int j = 0; j < tokensBefore.size(); j++)
						{
							if (SourceTokenSearcher.isNewLineToken(tokensBefore.get(j)))
							{
								flag = true;
								break;
							}
						}
					}
					if (!flag)
					{
						SourceTokenOperator.addBefore(this.Option, t, SourceTokenOperator.createReturnSourceToken());
					}
				}
			}
			return flag;
		}

		// Token: 0x060011E6 RID: 4582 RVA: 0x00316D08 File Offset: 0x00314F08
		private void removeComment(TSourceTokenList list, GFmtOpt opt, bool? removeComment, TSourceToken t, int index)
		{
			if (removeComment.Value)
			{
				if (t.ToString().StartsWith("/*+", StringComparison.Ordinal))
				{
					return;
				}
				t.astext = "";
				t.tokentype = ETokenType.ttwhitespace;
				if (t.TokensBefore != null)
				{
					t.TokensBefore.clear();
				}
				SourceTokenOperator.removeWhitespaceAndReturnFromStart(opt, list, index + 1);
			}
		}

		// Token: 0x060011E7 RID: 4583 RVA: 0x00316D68 File Offset: 0x00314F68
		private void processFormatFlag(TStatementList stmts)
		{
			if (stmts == null || stmts.size() == 0 || stmts.get(0) == null)
			{
				return;
			}
			TSourceToken startToken = stmts.get(0).startToken;
			if (startToken == null)
			{
				return;
			}
			TSourceTokenList container = startToken.container;
			bool flag = true;
			for (int i = 0; i < container.size(); i++)
			{
				TSourceToken tsourceToken = container.get(i);
				if ((tsourceToken.tokentype == ETokenType.ttsimplecomment || tsourceToken.tokentype == ETokenType.ttbracketedcomment) && tsourceToken.astext != null && (tsourceToken.astext.Contains("--begin_no_format") || tsourceToken.astext.Contains("--end_no_format")))
				{
					if (tsourceToken.astext.Contains("--begin_no_format"))
					{
						SourceTokenOperator.addBefore(this.Option, tsourceToken, SourceTokenOperator.createNoFormatFlagToken());
						flag = false;
					}
					else if (tsourceToken.astext.Contains("--end_no_format"))
					{
						SourceTokenOperator.addBefore(this.Option, tsourceToken, SourceTokenOperator.createNoFormatFlagToken());
						flag = true;
					}
				}
				else if (!flag)
				{
					SourceTokenOperator.addBefore(this.Option, tsourceToken, SourceTokenOperator.createNoFormatFlagToken());
				}
			}
		}

		// Token: 0x060011E8 RID: 4584 RVA: 0x00316E74 File Offset: 0x00315074
		private void alignLine(TStatementList stmts)
		{
			if (stmts == null || stmts.size() == 0)
			{
				return;
			}
			SourceTokenOperator.curColumnNumberVT(stmts.get(0).startToken);
			for (int i = 0; i < stmts.size(); i++)
			{
				TCustomSqlStatement tcustomSqlStatement = stmts.get(i);
				TSourceToken startToken = tcustomSqlStatement.startToken;
				TSourceToken endToken = tcustomSqlStatement.endToken;
				if (startToken != null)
				{
					if (startToken.posinlist - 1 > 0)
					{
						TSourceToken tsourceToken = startToken.container.get(startToken.posinlist - 1);
						if (SourceTokenSearcher.isNewLineToken(tsourceToken))
						{
							if (i > 0 && tsourceToken == stmts.get(i - 1).endToken)
							{
								if (!(tcustomSqlStatement is TMssqlGo) && !(tcustomSqlStatement is TMssqlSet))
								{
									SourceTokenOperator.addBefore(this.Option, startToken, SourceTokenOperator.createReturnSourceToken());
								}
							}
							else
							{
								tsourceToken.astext = AllStmtsFormatter.removeEndWhitespace(tsourceToken.astext);
							}
						}
					}
					SourceTokenOperator.curIndentLenVT(startToken);
				}
			}
		}

		// Token: 0x060011E9 RID: 4585 RVA: 0x00316F48 File Offset: 0x00315148
		private static string removeEndWhitespace(string text)
		{
			if (text == null)
			{
				return null;
			}
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = text.Length - 1; i >= 0; i--)
			{
				char c = text[i];
				if (c != ' ')
				{
					stringBuilder.Insert(0, c);
				}
			}
			return stringBuilder.ToString();
		}

		// Token: 0x060011EA RID: 4586 RVA: 0x00316F90 File Offset: 0x00315190
		public static void processEmptyLine(TStatementList stmts, GFmtOpt opt, bool isInBlock)
		{
			int posinlist = stmts.get(0).endToken.posinlist;
			TCustomSqlStatement tcustomSqlStatement = stmts.get(0);
			int length = SourceTokenOperator.curColumnNumberVT(tcustomSqlStatement.startToken);
			SourceTokenTextTempMediator mediator = MediatorFactory.getMediator<SourceTokenTextTempMediator>(typeof(SourceTokenTextTempMediator), opt.sessionId);
			for (int i = 1; i < stmts.size(); i++)
			{
				TCustomSqlStatement tcustomSqlStatement2 = stmts.get(i);
				TSourceToken startToken = tcustomSqlStatement2.startToken;
				TSourceToken endToken = tcustomSqlStatement2.endToken;
				TSourceToken tsourceToken = null;
				if (startToken != null && endToken != null && startToken.posinlist >= 0 && startToken.posinlist <= endToken.posinlist)
				{
					int posinlist2 = startToken.posinlist;
					posinlist = SourceTokenSearcher.lastNotWhitespaceAndReturnToken(endToken.container, tcustomSqlStatement.getStartToken().posinlist, posinlist + 1).posinlist;
					int num = 0;
					for (int j = posinlist + 1; j < posinlist2; j++)
					{
						TSourceToken tsourceToken2 = startToken.container.get(j);
						if (SourceTokenSearcher.isNewLineToken(tsourceToken2) || mediator.get(new int?(tsourceToken2.posinlist)) != null)
						{
							string text = mediator.get(new int?(tsourceToken2.posinlist));
							if (text == null)
							{
								text = tsourceToken2.astext;
							}
							int num2 = AllStmtsFormatter.countLine(text);
							num += num2;
							if (SourceTokenSearcher.isNewLineToken(tsourceToken2))
							{
								tsourceToken2.astext = "";
								tsourceToken2.tokentype = ETokenType.ttwhitespace;
							}
						}
						if (SourceTokenSearcher.isSimpleComment(tsourceToken2) && num > 0)
						{
							if (tsourceToken == null)
							{
								tsourceToken = tsourceToken2;
							}
							SourceTokenOperator.addBefore(opt, tsourceToken2, SourceTokenOperator.createReturnSourceToken());
						}
					}
					SourceTokenOperator.addBefore(opt, startToken, SourceTokenOperator.createReturnSourceToken());
					if (!(tcustomSqlStatement2 is TMssqlGo))
					{
						if (!opt.noEmptyLinesBetweenMultiSetStmts && AllStmtsFormatter.isSetStmt(tcustomSqlStatement) && AllStmtsFormatter.isSetStmt(tcustomSqlStatement2))
						{
							SourceTokenOperator.addBefore(opt, (tsourceToken == null) ? startToken : tsourceToken, SourceTokenOperator.createReturnSourceToken());
						}
						else if (isInBlock && opt.insertBlankLineInBatchSqls)
						{
							SourceTokenOperator.addBefore(opt, (tsourceToken == null) ? startToken : tsourceToken, SourceTokenOperator.createReturnSourceToken());
						}
						else if (opt.emptyLines != TEmptyLinesOption.EloRemove)
						{
							if (opt.emptyLines == TEmptyLinesOption.EloMergeIntoOne)
							{
								if (num > 1)
								{
									SourceTokenOperator.addBefore(opt, (tsourceToken == null) ? startToken : tsourceToken, SourceTokenOperator.createReturnSourceToken());
								}
							}
							else if (opt.emptyLines == TEmptyLinesOption.EloPreserve)
							{
								for (int k = (tsourceToken == null) ? 1 : 2; k < num; k++)
								{
									SourceTokenOperator.addBefore(opt, (tsourceToken == null) ? startToken : tsourceToken, SourceTokenOperator.createReturnSourceToken());
								}
							}
						}
					}
					SourceTokenOperator.addBefore(opt, startToken, SourceTokenOperator.createWhitespaceSourceToken(length));
					posinlist = endToken.posinlist;
					if (!(tcustomSqlStatement2 is TMssqlGo))
					{
						tcustomSqlStatement = tcustomSqlStatement2;
					}
				}
			}
		}

		// Token: 0x060011EB RID: 4587 RVA: 0x00317218 File Offset: 0x00315418
		private static int countLine(string text)
		{
			if (text == null || text.Length == 0)
			{
				return 0;
			}
			int num = 0;
			for (int i = 0; i < text.Length; i++)
			{
				if (text[i] == '\n')
				{
					num++;
				}
			}
			return num;
		}

		// Token: 0x060011EC RID: 4588 RVA: 0x00317255 File Offset: 0x00315455
		private static bool isSetStmt(TCustomSqlStatement stmt)
		{
			return stmt is TMssqlSet || stmt is TDb2SetStmt || stmt is TMySQLSet || stmt is TMssqlDeclare;
		}

		// Token: 0x060011ED RID: 4589 RVA: 0x0031727C File Offset: 0x0031547C
		private void processTab(TStatementList stmts)
		{
			if (!this.Option.useTab)
			{
				return;
			}
			for (int i = 0; i < stmts.size(); i++)
			{
				TCustomSqlStatement tcustomSqlStatement = stmts.get(i);
				TSourceToken startToken = tcustomSqlStatement.startToken;
				TSourceToken endToken = tcustomSqlStatement.endToken;
				if (startToken != null && endToken != null && startToken.posinlist >= 0 && startToken.posinlist < endToken.posinlist)
				{
					TSourceToken firstToken = startToken;
					for (int j = startToken.posinlist + 1; j <= endToken.posinlist; j++)
					{
						TSourceToken tsourceToken = startToken.container.get(j);
						if (this.containNewLine(firstToken, tsourceToken))
						{
							int num = SourceTokenOperator.curIndentLenVT(tsourceToken) % this.Option.tabSize;
							if (num > 0)
							{
								SourceTokenOperator.addBefore(this.Option, tsourceToken, SourceTokenOperator.createWhitespaceSourceToken(this.Option.tabSize - num));
							}
						}
						firstToken = tsourceToken;
					}
				}
			}
		}

		// Token: 0x060011EE RID: 4590 RVA: 0x00317360 File Offset: 0x00315560
		private bool containNewLine(TSourceToken firstToken, TSourceToken secondToken)
		{
			if (SourceTokenSearcher.isNewLineToken(firstToken))
			{
				return true;
			}
			TSourceTokenList tokensAfter = firstToken.TokensAfter;
			if (tokensAfter.size() > 0)
			{
				for (int i = 0; i < tokensAfter.size(); i++)
				{
					if (SourceTokenSearcher.isNewLineToken(tokensAfter.get(i)))
					{
						return true;
					}
				}
			}
			TSourceTokenList tokensBefore = secondToken.TokensBefore;
			if (tokensBefore.size() > 0)
			{
				for (int j = 0; j < tokensBefore.size(); j++)
				{
					if (SourceTokenSearcher.isNewLineToken(tokensBefore.get(j)))
					{
						return true;
					}
				}
			}
			return false;
		}

		// Token: 0x060011EF RID: 4591 RVA: 0x003173DC File Offset: 0x003155DC
		private void processLineNumber(TStatementList stmts)
		{
			if (stmts.size() == 0)
			{
				return;
			}
			GFmtOpt option = this.Option;
			if (!option.linenumberEnabled)
			{
				return;
			}
			TSourceTokenList container = stmts.get(0).startToken.container;
			AllStmtsFormatter.SourceTokenVisitor sourceTokenVisitor = new AllStmtsFormatter.SourceTokenVisitorAnonymousInnerClass(this);
			this.visitAllSourceTokens(container, sourceTokenVisitor);
			int length = ((int)sourceTokenVisitor.Object).ToString().Length;
			AllStmtsFormatter.SourceTokenVisitor visitor = new AllStmtsFormatter.SourceTokenVisitorAnonymousInnerClass2(this, option, length);
			this.visitAllSourceTokens(container, visitor);
			TSourceToken needAddToken = new TSourceToken(this.buildLineNumber(option.linenumberZeroBased ? 0 : 1, length, option.linenumberLeftMargin, option.linenumberRightMargin));
			SourceTokenOperator.addBefore(this.Option, container.get(0), needAddToken);
		}

		// Token: 0x060011F0 RID: 4592 RVA: 0x0031748C File Offset: 0x0031568C
		private string buildLineNumber(int lineCount, int lineNumberMaxLength, int leftMargin, int rightMargin)
		{
			StringBuilder stringBuilder = new StringBuilder();
			if (leftMargin > 0)
			{
				char[] array = new char[leftMargin];
				Utils.Fill<char>(array, ' ');
				stringBuilder.Append(array);
			}
			int num = lineNumberMaxLength - lineCount.ToString().Length;
			if (num > 0)
			{
				char[] array2 = new char[num];
				Utils.Fill<char>(array2, '0');
				new string(array2);
				stringBuilder.Append(array2);
			}
			stringBuilder.Append(lineCount);
			if (rightMargin > 0)
			{
				char[] array3 = new char[rightMargin];
				Utils.Fill<char>(array3, ' ');
				stringBuilder.Append(array3);
			}
			return stringBuilder.ToString();
		}

		// Token: 0x060011F1 RID: 4593 RVA: 0x0031751C File Offset: 0x0031571C
		private void visitAllSourceTokens(TSourceTokenList list, AllStmtsFormatter.SourceTokenVisitor visitor)
		{
			for (int i = 0; i < list.size(); i++)
			{
				TSourceToken tsourceToken = list.get(i);
				TSourceTokenList tokensBefore = tsourceToken.TokensBefore;
				for (int j = 0; j < tokensBefore.size(); j++)
				{
					TSourceToken tsourceToken2 = tokensBefore.get(j);
					TSourceToken tsourceToken3 = visitor.visit(tsourceToken2);
					if (tsourceToken3 != null)
					{
						tsourceToken2.TokensAfter.add(tsourceToken3);
					}
				}
				TSourceToken tsourceToken4 = visitor.visit(tsourceToken);
				TSourceTokenList tokensAfter = tsourceToken.TokensAfter;
				for (int k = 0; k < tokensAfter.size(); k++)
				{
					TSourceToken tsourceToken5 = tokensAfter.get(k);
					TSourceToken tsourceToken6 = visitor.visit(tsourceToken5);
					if (tsourceToken6 != null)
					{
						tsourceToken5.TokensAfter.add(tsourceToken6);
					}
				}
				if (tsourceToken4 != null)
				{
					tsourceToken.TokensAfter.add(tsourceToken4);
				}
			}
		}

		// Token: 0x0200044C RID: 1100
		private class SourceTokenVisitorAnonymousInnerClass : AllStmtsFormatter.SourceTokenVisitor
		{
			// Token: 0x0600298C RID: 10636 RVA: 0x0033E552 File Offset: 0x0033C752
			public SourceTokenVisitorAnonymousInnerClass(AllStmtsFormatter outerInstance)
			{
				this.outerInstance = outerInstance;
				this.lineCount = new int?(0);
			}

			// Token: 0x0600298D RID: 10637 RVA: 0x0033E570 File Offset: 0x0033C770
			public virtual TSourceToken visit(TSourceToken token)
			{
				if (SourceTokenSearcher.isNewLineToken(token))
				{
					if (token.astext.Equals("\n\n"))
					{
						this.lineCount++;
					}
					this.lineCount++;
				}
				return null;
			}

			// Token: 0x17000987 RID: 2439
			// (get) Token: 0x0600298E RID: 10638 RVA: 0x0033E5F6 File Offset: 0x0033C7F6
			public virtual object Object
			{
				get
				{
					return this.lineCount;
				}
			}

			// Token: 0x04001EC9 RID: 7881
			private readonly AllStmtsFormatter outerInstance;

			// Token: 0x04001ECA RID: 7882
			private int? lineCount;
		}

		// Token: 0x0200044D RID: 1101
		private class SourceTokenVisitorAnonymousInnerClass2 : AllStmtsFormatter.SourceTokenVisitor
		{
			// Token: 0x0600298F RID: 10639 RVA: 0x0033E603 File Offset: 0x0033C803
			public SourceTokenVisitorAnonymousInnerClass2(AllStmtsFormatter outerInstance, GFmtOpt opt, int lineNumbersMaxLength)
			{
				this.outerInstance = outerInstance;
				this.opt = opt;
				this.lineNumbersMaxLength = lineNumbersMaxLength;
				this.lineCount = (opt.linenumberZeroBased ? 1 : 2);
			}

			// Token: 0x06002990 RID: 10640 RVA: 0x0033E634 File Offset: 0x0033C834
			public virtual TSourceToken visit(TSourceToken token)
			{
				if (token.tokentype == ETokenType.ttbracketedcomment || token.tokentype == ETokenType.ttsimplecomment)
				{
					string[] array = token.astext.Split(new char[]
					{
						'\n'
					});
					StringBuilder stringBuilder = new StringBuilder();
					stringBuilder.Append(array[0]);
					if (array.Length > 1)
					{
						for (int i = 1; i < array.Length; i++)
						{
							stringBuilder.Append("\n");
							stringBuilder.Append(this.outerInstance.buildLineNumber(this.lineCount, this.lineNumbersMaxLength, this.opt.linenumberLeftMargin, this.opt.linenumberRightMargin));
							this.lineCount++;
							stringBuilder.Append(array[i]);
						}
					}
					token.astext = stringBuilder.ToString();
				}
				if (SourceTokenSearcher.isNewLineToken(token))
				{
					if (!token.astext.Equals("\n\n"))
					{
						TSourceToken result = new TSourceToken(this.outerInstance.buildLineNumber(this.lineCount, this.lineNumbersMaxLength, this.opt.linenumberLeftMargin, this.opt.linenumberRightMargin));
						this.lineCount++;
						return result;
					}
					AllStmtsFormatter allStmtsFormatter = this.outerInstance;
					int num = this.lineCount;
					this.lineCount = num + 1;
					string str = allStmtsFormatter.buildLineNumber(num, this.lineNumbersMaxLength, this.opt.linenumberLeftMargin, this.opt.linenumberRightMargin);
					AllStmtsFormatter allStmtsFormatter2 = this.outerInstance;
					num = this.lineCount;
					this.lineCount = num + 1;
					string str2 = allStmtsFormatter2.buildLineNumber(num, this.lineNumbersMaxLength, this.opt.linenumberLeftMargin, this.opt.linenumberRightMargin);
					token.astext = "\n" + str + "\n" + str2;
				}
				return null;
			}

			// Token: 0x17000988 RID: 2440
			// (get) Token: 0x06002991 RID: 10641 RVA: 0x0033E7EA File Offset: 0x0033C9EA
			public virtual object Object
			{
				get
				{
					return null;
				}
			}

			// Token: 0x04001ECB RID: 7883
			private readonly AllStmtsFormatter outerInstance;

			// Token: 0x04001ECC RID: 7884
			private GFmtOpt opt;

			// Token: 0x04001ECD RID: 7885
			private int lineNumbersMaxLength;

			// Token: 0x04001ECE RID: 7886
			private int lineCount;
		}

		// Token: 0x0200044E RID: 1102
		public interface SourceTokenVisitor
		{
			// Token: 0x17000989 RID: 2441
			// (get) Token: 0x06002992 RID: 10642
			object Object { get; }

			// Token: 0x06002993 RID: 10643
			TSourceToken visit(TSourceToken token);
		}
	}
}
